package com.liangtian.mdm.dm.tree.controller;

import com.alibaba.fastjson.JSON;
import com.liangtian.mdm.base.controller.BaseController;
import com.liangtian.mdm.dm.common.util.RequestUtils;
import com.liangtian.mdm.dm.tree.model.Tree;
import com.liangtian.mdm.dm.tree.service.TreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/tree")
public class TreeController extends BaseController {

    @Autowired
    private TreeService treeService;

    @RequestMapping(value = "/queryChildren", method = RequestMethod.POST)
    @ResponseBody
    public String queryChildren(HttpServletRequest request) {
        //查询条件
        Map<String, Object> param = RequestUtils.paramToMap(request);
//		System.out.println(param);
//		System.out.println("=========queryChildren==========");
        List<Tree> children = treeService.queryChildren(param);

        return JSON.toJSONString(children);
    }


    @RequestMapping(value = "/getChildrenById", method = RequestMethod.POST)
    @ResponseBody
    public String getChildrenById(HttpServletRequest request) {
        //查询条件
        Map<String, Object> param = RequestUtils.paramToMap(request);
//		System.out.println(param);
//		System.out.println("=========queryChildren==========");
        List<Tree> children = treeService.getChildrenById(param);

        return JSON.toJSONString(children);
    }


    @RequestMapping(value = "/queryTreeChildren", method = RequestMethod.POST)
    @ResponseBody
    public String queryTreeChildren(HttpServletRequest request) {
        //查询条件
        Map<String, Object> param = RequestUtils.paramToMap(request);
//		System.out.println("=========queryChildren==========");
        List<Tree> children = treeService.queryTreeChildren(param);

        return JSON.toJSONString(children);
    }
}
